home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 113 / gfatip06 / gfatip06.txt next >
Text File  |  1987-07-04  |  10KB  |  204 lines

  1.  
  2.  
  3.                                                    July 4, 1987
  4.  
  5.  
  6.                            GFATIP06.DOC
  7.  
  8.                         by John B. Holder
  9.                      Senior Software Engineer
  10.                      Marathon Computer Press
  11.            Asst. Sysop on GEnie's MichTron Roundtable
  12.  
  13.  
  14.      This is the 6th in a planned series of GFA Tip files.  The 
  15. topic of this issue is "Multi-Tasking with GFA Basic, To Be or Not 
  16. to Be".  Before we get into the nitty gritty of the subject, a bit 
  17. of background is necessary first.  If you are an experienced 
  18. programmer with a background in Multi-Tasking operating systems 
  19. such as UNIX then please excuse the intro to the subject.
  20.  
  21.  
  22.                   Multi-Tasking Myths-vs-Reality
  23.  
  24. Myth:
  25.  
  26.      When Multi-tasking on a one CPU system, you actually run 
  27. several concurrent processes all at the same time.
  28.  
  29. Reality:
  30.  
  31.      A single CPU system that Multi-Tasks actually allows several 
  32. jobs to be started and be scheduled concurrently, however the 
  33. CPU's time is actually shared among the processes.  This is where 
  34. you might have heard the term "Time-Sharing System".  The 
  35. operating system creates several shells for ongoing processes, and 
  36. switches among the active scheduled processes in such a manner as 
  37. to give the impression of simultaneous execution.  There are 
  38. several excellent software packages that use this scheme of 
  39. process "sharing" on the ST.  Most notably are David Beckemeyer's 
  40. MT C Shell, Flight Simulator, and Silent Service to name a few.  
  41. So the big question at this point is, "Why Not GFA Basic Too?"  
  42. Well, the answer is "It is possible if several factors are taken 
  43. into consideration and worked out properly."  So, now let's get on 
  44. with the background of a Multi-Tasking Operating System or 
  45. Application.
  46.  
  47.      At the heart of any Multi-Tasking application is what is 
  48. known as a Kernel.  The Kernel must control access to the 
  49. computer, manage memory assets, maintain the file system, and 
  50. allocate available resources to the calling procedures or users.  
  51. It is analogous to a traffic cop.  This is the heart of the system.  
  52. Here is where all of the control of the CPU takes place, and it 
  53. must take place invisibly to the user, so they need not ever be 
  54. aware of it's presence.
  55.  
  56.      Now you might ask, how does this Kernel thing know when to 
  57. activate and de-activate a process?  Well, that's where you as a 
  58. programmer or user would step in.  Typically TSS {time-sharing 
  59. systems} allocate a "Quantum" to active processes.  A Quantum is 
  60. nothing more than a chunk of time to be used by a process.  In a 
  61. round-robin type of scheduler each process can be assigned the 
  62. same Quantum, or the individual processes can be awarded varying 
  63. Quantums based on a prioritization scheme.  For example:  A 
  64. business is running a series of jobs on a Multi-Tasking system and 
  65. the operator decides to assign a higher priority to the Payroll 
  66. job for obvious reasons.  By doing so, he/she in effect gives the 
  67. process {Payroll} a larger Quantum.  By now you might be thinking, 
  68. "That's all fine and good, but that's a much more expensive system 
  69. than my little ST!".  This is very true, but with the speed of the 
  70. MC68000, and some built in features of the ST system, coupled 
  71. with the sheer speed of instruction handling provided by GFA 
  72. Basic, you can actually schedule multiple processes to be handled 
  73. at a single time.  So without further ado, let's talk a bit about 
  74. setting up limited multi-tasking within a running application 
  75. written in GFA Basic.
  76.  
  77.      There are essentially two ways that you might initiate this 
  78. type of job handling on the ST with GFA Basic.  The first, {which 
  79. will suit most tasks} is to use the Timer command from within a 
  80. master scheduling procedure {Dispatcher}, or to call on a routine 
  81. that has been written in C or 68000 Assembler and compiled or 
  82. assembled to do the job for you using the C or Call commands.  The 
  83. method used in the example compiled program utilizes the first 
  84. method.  While the internal handling of the processes is 
  85. undoutedly the easiest, it is also the less flexible at least in 
  86. terms of running multiple programs versus multiple processes.  It 
  87. is doubtful that you would be able to successfully run multiple 
  88. applications at once without the control of an exterior shell 
  89. program {kernel}.  But then again even the applications mentioned 
  90. above that Multi-Task do not run several programs at once, {the 
  91. exception is Beckemeyer's MT C Shell, it actually will run several 
  92. applications at once from a parent Command Shell and Kernel}.  So 
  93. here in the next section I'll rough up a diagram of what is 
  94. necessary for an application to include to make Multi-Tasking a 
  95. reality.  Oh by the way, this is a very rough approximation of 
  96. what must happen.  I'll leave the more involved details to your 
  97. own ingenuity.
  98.  
  99.                               START
  100.                                 |
  101.               Job I/O and Selection {Perhaps a CLI}
  102.                                 |
  103.             Pre-Process and assign PID {process ID's}
  104.                                 |
  105.  
  106.                                 |
  107.                             The Kernel
  108.              Here we assign the Quantum for Processes
  109.         and dispatch the running of those processes until
  110.                          they are ended.
  111.                   /             |           \
  112.           Process 1         Process 2      Process 3
  113.  
  114.                                 |
  115.       As processes end, new ones may be assigned as desired.
  116.                                 |
  117.                 Until no more processes are active
  118.                                 |
  119.                           End of Program
  120.  
  121.  
  122.      I told you it was ROUGH!  But I think it gets the idea across 
  123. nicely enough.  So at this point you might ask "That's fine and 
  124. dandy, but why would I ever want to Multi-Task anyway?".  If you 
  125. have ever felt impatient while your Terminal program sits there 
  126. staring at you with it's great big pale irridescent eye while 
  127. downloading a HUGE file from a BBS, and you were powerless to do 
  128. anything but wait till it was finished you will understand the 
  129. need and applicability of Multi-Tasking.  With Multi-Tasking on 
  130. your side, you could perhaps drop out and play a game while the 
  131. file is finishing in the background.  Or take the instance of the 
  132. games {Silent Service or Flight Simulator II} mentioned above.  
  133. They are both very, very involved and maintain several processes 
  134. at once, thus necessitating a form of Multi-Tasking.  Who likes 
  135. looking at a game screen that just does one thing at a time?  Not 
  136. Me!  I want action with things moving all over the place and 
  137. sound, and, and, well you get the idea.  Any one that has used or 
  138. seen Tim Purves's BBS will also get an appreciation for what can 
  139. be accomplished with Multi-Tasking.
  140.  
  141.      The little demo program I've included in this ARChive will 
  142. give you a glimpse of a brand of Multi-Tasking that is possible 
  143. with GFA Basic.  The Processes may be independently killed by 
  144. pressing either the 1,2,or 3 keys on the keyboard, or you may 
  145. press the right mouse button to stop the currently active process.  
  146. When you do so, an alert box appears and asks if you would like to 
  147. kill the process.  The number of the active process appears in the 
  148. upper right hand corner of the screen and also in the alert box.  
  149. At that time, you may either kill it or allow it to continue.  I 
  150. opted to use the AES and alert boxes so that when chosen all 
  151. processes would STOP momentarily so that you could in effect see a 
  152. freeze frame of the activity.  I could have used a non destructive 
  153. process that allowed the activity to continue while waiting for 
  154. your response, but that was not the intent of the demo.  If you 
  155. have killed a process and desire to start it up again, just press 
  156. the 1,2,or 3 keys on the keyboard.  The numbers relate directly to 
  157. the processes and windows represented on the screen.  When all of 
  158. the processes are terminated, the program will exit normally to 
  159. the GEM Desktop.
  160.  
  161.                           The Question?
  162.  
  163.      Why, you might ask yourself, is this guy doing this, and why 
  164. has he not uploaded the source code to the demo?  The answer to 
  165. that is that I want to see what sort of reaction you all have 
  166. about this.  If there is enough interest in this subject, perhaps 
  167. and I do mean maybe, I can develop a Kernel that will handle 
  168. several types of scheduling for you.  I'm not totally confident in 
  169. that theory as of yet, but without any interest in the user and 
  170. programmer community I will definitely not pursue it any further.  
  171. I just thought that some {hopefully many} of you would be 
  172. interested in a product that could be merged into your own 
  173. programs and would {nearly} painlessly dispatch Multi-Tasking for 
  174. you.  Since I am not sure as to where this demo will end up, the 
  175. contact points are listed below:
  176.  
  177.     On GEnie send Email to address = >  GRIFJOHN
  178.                       or                MCP.TECH01
  179.  
  180.                       and
  181.  
  182.     On Compuserve send Email to address = > 75766,505
  183.  
  184.      At this point it is just in the idea stage, but from the 
  185. above discussion and included demo program, you can see that it is 
  186. possible even if in a limited fashion.  Some of you may even run 
  187. with the idea yourselves.  If you do, I wish you all of the luck 
  188. in the world, {you're going to need it, heh...heh..}.
  189.  
  190.      For all of you doubting Thomas'es out there, it wasn't too 
  191. long ago that all I heard on GEnie was "Gee... GFA Basic sure 
  192. would be nice if you could just use Dialog Boxes...", some even 
  193. said it couldn't be done.  That's why I wrote The GFA Basic 
  194. Companion(tm).  So perhaps this program's for you!  At any rate, 
  195. please spend a dime or two and leave me a note on one of the two 
  196. mentioned billboards, or you can drop me a letter at:
  197.  
  198.                      Marathon Computer Press
  199.                           P.O. Box 68503
  200.                 Virginia Beach, VA  23455-9433
  201.  
  202.                 Your comments will be appreciated.
  203.  
  204.